package com.design.adnroid.campussecondarytrading.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import com.design.adnroid.campussecondarytrading.AppContext;

import java.util.ArrayList;

public class PersonalActivity extends AppCompatActivity {

    private ListView listView;
    private ArrayList arrayList;
    private ArrayAdapter arrayAdapter;
    private Button button;
    private TextView tvName, tvUserName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_personal);

        initID();

        initView();

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String str = (String) parent.getItemAtPosition(position);

                Intent intent = new Intent();
                switch (position) {
                    case 0:
                        intent.setClass(PersonalActivity.this, PersonalEditActivity.class);
                        startActivity(intent);
                        finish();
                        break;
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                    case 7:
                        intent.setClass(PersonalActivity.this, GoodsListActivity.class);
                        intent.putExtra("intentName", str);
                        intent.putExtra("intentPosition", String.valueOf(position));
                        startActivity(intent);
                        break;
                    default:
                        Toast.makeText(getApplicationContext(), "点击无效！", Toast.LENGTH_LONG).show();
                        return;
                }
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(PersonalActivity.this,LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void initID() {
        listView = (ListView) findViewById(R.id.personal_listView);
        button = findViewById(R.id.personal_button);
        tvName = (TextView) findViewById(R.id.personal_name);
        tvUserName = (TextView) findViewById(R.id.personal_userName);
    }

    private void initView() {

        tvUserName.setText(AppContext.getUserName());
        tvName.setText(AppContext.getName());

        arrayList = new ArrayList();
        arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, arrayList);

        arrayList.add(getString(R.string.a_personal_edit));
        arrayList.add(getString(R.string.a_personal_issued));
        arrayList.add(getString(R.string.a_personal_buyed));
        arrayList.add(getString(R.string.a_personal_order));
        arrayList.add(getString(R.string.a_personal_trading));
        arrayList.add(getString(R.string.a_personal_finished));
        arrayList.add(getString(R.string.a_personal_unIssued));
        arrayList.add(getString(R.string.a_personal_unselled));
        listView.setAdapter(arrayAdapter);
    }
}
